/*
  Copyright (c) 2020 BeiJing HowLink Ltd
*/

#ifndef cJSON__h
#define cJSON__h


#define coreapi_AddItemToArray           0x0800d038 +1
#define coreapi_AddItemToObject          0x0800d064 +1
#define coreapi_CreateArray      				 0x0800d094 +1
#define coreapi_CreateBool               0x0800d0a6 +1
#define coreapi_CreateNull               0x0800d1aa +1
#define coreapi_CreateNumber             0x0800d1bc +1
#define coreapi_CreateObject             0x0800d1e0 +1
#define coreapi_CreateString     				 0x0800d1f2 +1
#define coreapi_GetArrayItem             0x0800d350 +1
#define coreapi_GetArraySize             0x0800d362 +1
#define coreapi_GetObjectItem            0x0800d380 +1

#define coreapi_JSON_Delete              0x0800d260 +1
#define coreapi_JSON_Parse             	 0x0800d408 +1
#define coreapi_JSON_Print       				 0x0800d440 +1
    
/* The cJSON structure: */
typedef struct cJSON {
    struct cJSON *next,*prev;    /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
    struct cJSON *child;        /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */

    int type;                    /* The type of the item, as above. */

    char *valuestring;            /* The item's string, if type==cJSON_String */
    int valueint;                /* The item's number, if type==cJSON_Number */
    double valuedouble;            /* The item's number, if type==cJSON_Number */

    char *string;                /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
} cJSON;

#define cJSON_CreateNull(void)    		 				((cJSON* (*)(void))(coreapi_CreateNull))(void) 
#define cJSON_CreateBoll(b)    		 				    ((cJSON* (*)(int))(coreapi_CreateBool))(b) 
#define cJSON_CreateArray(void)    		 				((cJSON* (*)(void))(coreapi_CreateArray))(void) 
#define cJSON_CreateObject(void)    		 			((cJSON* (*)(void))(coreapi_CreateObject))(void)  
#define cJSON_CreateString(arg)     					((cJSON* (*)(char *))(coreapi_CreateString))(arg)  
#define cJSON_CreateNumber(arg)     					((cJSON* (*)(double))(coreapi_CreateNumber))(arg)  
#define cJSON_AddItemToArray(array,object)    ((void (*)(cJSON *,cJSON *))(coreapi_AddItemToArray))(array,object)
#define cJSON_AddItemToObject(object,name,s)  ((void (*)(cJSON *,const char *,cJSON *))(coreapi_AddItemToObject))(object,name,s)

#define cJSON_GetArrayItem(object,i)          ((cJSON* (*)(cJSON *,int))(coreapi_GetArrayItem))(object,i)
#define cJSON_GetArraySize(object)            ((int    (*)(cJSON *))(coreapi_GetArraySize))(object)
#define cJSON_GetObjectItem(object,s)         ((cJSON* (*)(cJSON *,const char *))(coreapi_GetObjectItem))(object,s)

#define cJSON_Parse(arg)           					  ((cJSON* (*)(const char *))(coreapi_JSON_Parse))(arg)
#define cJSON_Print(arg)           					  ((char * (*)(cJSON*))(coreapi_JSON_Print))(arg)
#define cJSON_Delete(arg)           					((void   (*)(cJSON*))(coreapi_JSON_Delete))(arg)

#endif
